﻿using System;
using UnityEngine;

namespace Core
{
    public class DelayItem : Core.Component
    {
        public bool IsComplete { get; private set; }

        public Action Func;
        public float Interval;

        private float elapsedTime;

        public void Start()
        {
            elapsedTime = 0;
            IsComplete = false;
        }

        public void Update()
        {
            if (IsComplete) return;

            elapsedTime += Time.deltaTime;

            if (elapsedTime >= Interval)
            {
                elapsedTime -= Interval;
                Func();

                IsComplete = true;
            }
        }

        public override void Dispose()
        {
            if (IsDisposed) return;
            base.Dispose();

            Func = null;
            Interval = 0;
        }
    }
}
